//
// Created by hugan on 2020/11/16.
//
#include "../dllJni/HRobotJni.cpp"
#include "../common/CommonUtil.h"

void mouseMove(int x, int y) {
    CommonUtil::printRes("mouseMove",
                         Java_com_hup_utils_commons_hardware_HRobotJni_mouseMove(nullptr, nullptr, x, y));
}
void mouseWheel(int value, bool isHorizontal) {
    CommonUtil::printRes("mouseWheel",
                         Java_com_hup_utils_commons_hardware_HRobotJni_mouseWheel(nullptr, nullptr, value, isHorizontal));
}
void showMouse() {
    CommonUtil::printRes("showMouse",
                         Java_com_hup_utils_commons_hardware_HRobotJni_showMouse(nullptr, nullptr));
}

void lockWorkStation() {
    CommonUtil::printRes("lockWorkStation",
                         Java_com_hup_utils_commons_hardware_HRobotJni_lockWorkStation(nullptr, nullptr));
}

void testVolume() {
    Java_com_hup_utils_commons_hardware_HRobotJni_createGlobalVolumeUtil(nullptr, nullptr);
    Java_com_hup_utils_commons_hardware_HRobotJni_createGlobalVolumeUtil(nullptr, nullptr);
//    Java_com_hup_utils_commons_hardware_HRobotJni_releaseGlobalVolumeUtil(nullptr, nullptr);
    cout << "isMute="
         << CommonUtil::toCBool(Java_com_hup_utils_commons_hardware_HRobotJni_isMute(nullptr, nullptr))
         << endl;
    cout << "getVolume="
         << Java_com_hup_utils_commons_hardware_HRobotJni_getVolume(nullptr, nullptr)
         << endl;
    Java_com_hup_utils_commons_hardware_HRobotJni_releaseGlobalVolumeUtil(nullptr, nullptr);
}

void testMediaPlay() {
    Java_com_hup_utils_commons_hardware_HRobotJni_mediaPlayPause(nullptr, nullptr);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
void testGetKeyboardState() {
    while (1) { // NOLINT(modernize-use-bool-literals)
        jbyte res = Java_com_hup_utils_commons_hardware_HRobotJni_getKeyboardState(nullptr, nullptr);
        cout << "res=" << static_cast<int>(res) << endl;
        Sleep(1000);
    }
}
#pragma clang diagnostic pop

void testWindowDisplayAffinity() {
    // 创建窗口
    HWND hwnd = CreateWindowEx(
            0, "STATIC", "test",
            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
            300, 150, nullptr, nullptr, nullptr, nullptr
    );
    if (hwnd == nullptr) {
        std::cerr << "Window creation failed." << std::endl;
        return;
    }

    // 启用防截屏
    //Java_com_hup_utils_commons_hardware_HRobotJni_setWindowDisplayAffinity(
    //        nullptr, nullptr, (jlong) hwnd, (jint) WDA_EXCLUDEFROMCAPTURE);

    //置顶
    SetWindowPos(hwnd, HWND_TOPMOST, 1, 1, 300, 150, SWP_SHOWWINDOW);
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

     //启用防截屏 // show前后 调用都可以
    Java_com_hup_utils_commons_hardware_HRobotJni_setWindowDisplayAffinity(
            nullptr, nullptr, (jlong) hwnd, (jint) WDA_EXCLUDEFROMCAPTURE);

    MSG msg = {0};
    while (GetMessage(&msg, nullptr, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

int main() {
    cout << "main.st" << endl;
    //Sleep(1000);//延时,用于检查其他程序前置候的运行结果
    //cout << "delay.out" << endl;

    //mouseMove(100, 200);
    //showMouse();
//    mouseWheel(-3, false);
//    mouseWheel(2, true);
//    lockWorkStation();
//    testVolume();
//    testMediaPlay();
//    testGetKeyboardState();
    testWindowDisplayAffinity();

    cout << "main.ed" << endl;
    return 0;
}